package com.lanchetech.admin.controller;

import com.lanchetech.admin.aop.OperatorLog;
import com.lanchetech.admin.service.BargainService;
import com.lanchetech.admin.service.MarketingService;
import com.lanchetech.bean.request.*;
import com.lanchetech.bean.response.*;
import com.lanchetech.bean.vo.*;
import com.lanchetech.entity.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "营销管理接口", tags = "营销管理接口")
@RequestMapping("/api/marketing")
@RestController
public class MarketingController {

    @Autowired
    MarketingService marketingService;

    @Autowired
    BargainService bargainService;

    @ApiOperation("获取秒杀商品分页")
    @PreAuthorize("hasAuthority('marketing.kill.index')")
    @PostMapping("/getKillActivityPage")
    public ResultData<BasePageResp<KillActivityResp>> getKillActivityPage(@RequestBody PageReq req) {
        return marketingService.getKillActivityPage(req);
    }

    @OperatorLog("添加或编辑秒杀活动")
    @ApiOperation("添加或编辑秒杀活动")
    @PreAuthorize("hasAuthority('marketing.kill.index.edit.auth')")
    @PostMapping("/editKillActivity")
    public BaseResp editKillActivity(@RequestBody KillActivityEditVO req) {
        return marketingService.editKillActivity(req);
    }

    @ApiOperation("获取秒杀活动详情")
    @PreAuthorize("hasAuthority('marketing.kill.kill-edit')")
    @GetMapping("/getKillActivityDetail")
    public ResultData<KillActivityEditResp> getKillActivityDetail(@RequestParam("id") Long id) {
        return marketingService.getKillActivityDetail(id);
    }

    @ApiOperation("获取积分奖励分页")
    @PreAuthorize("hasAuthority('marketing.coin.reward')")
    @PostMapping("/getCoinRewardPage")
    public ResultData<BasePageResp<CoinRewardResp>> getCoinRewardPage(@RequestBody PageReq req) {
        return marketingService.getCoinRewardPage(req);
    }

    @OperatorLog("添加或编辑积分奖励")
    @ApiOperation("添加或编辑积分奖励")
    @PreAuthorize("hasAuthority('marketing.coin.reward.edit.auth')")
    @PostMapping("/editCoinReward")
    public BaseResp editCoinReward(@RequestBody List<CoinReward> req) {
        return marketingService.editCoinReward(req);
    }

    @OperatorLog("删除积分奖励")
    @ApiOperation("删除积分奖励")
    @PreAuthorize("hasAuthority('marketing.coin.reward.delete.auth')")
    @GetMapping("/deleteCoinReward")
    public BaseResp deleteCoinReward(@RequestParam("id") Long id) {
        return marketingService.deleteCoinReward(id);
    }

    @ApiOperation("获取积分抵扣分页")
    @PreAuthorize("hasAuthority('marketing.coin.deduction')")
    @PostMapping("/getCoinDeductionPage")
    public ResultData<BasePageResp<CoinDeductionResp>> getCoinDeductionPage(@RequestBody PageReq req) {
        return marketingService.getCoinDeductionPage(req);
    }

    @OperatorLog("添加或编辑积分抵扣")
    @ApiOperation("添加或编辑积分抵扣")
    @PreAuthorize("hasAuthority('marketing.coin.deduction.edit.auth')")
    @PostMapping("/editCoinDeduction")
    public BaseResp editCoinDeduction(@RequestBody List<CoinDeduction> req) {
        return marketingService.editCoinDeduction(req);
    }

    @OperatorLog("删除积分抵扣")
    @ApiOperation("删除积分抵扣")
    @PreAuthorize("hasAuthority('marketing.coin.deduction.delete.auth')")
    @GetMapping("/deleteCoinDeduction")
    public BaseResp deleteCoinDeduction(@RequestParam("id") Long id) {
        return marketingService.deleteCoinDeduction(id);
    }

    @OperatorLog("添加或编辑积分使用条件设置")
    @ApiOperation("添加或编辑积分使用条件设置")
    @PreAuthorize("hasAuthority('marketing.coin.coin-setting.edit.auth')")
    @PostMapping("/editCoinSetting")
    public BaseResp editCoinSetting(@RequestBody CoinSetting coinSetting) {
        return marketingService.editCoinSetting(coinSetting);
    }

    @OperatorLog("删除积分使用条件设置")
    @ApiOperation("删除积分使用条件设置")
    @PreAuthorize("hasAuthority('marketing.coin.coin-setting.edit.auth')")
    @GetMapping("/deleteCoinSetting")
    public BaseResp deleteCoinSetting(@RequestParam("id") Long id) {
        return marketingService.deleteCoinSetting(id);
    }

    @ApiOperation("获取积分使用条件分页")
    @PreAuthorize("hasAuthority('marketing.coin.coin-setting')")
    @PostMapping("/getCoinSettingPage")
    public ResultData<BasePageResp<CoinSetting>> getCoinSettingPage(@RequestBody BasePageReq req) {
        return marketingService.getCoinSettingPage(req);
    }

    @ApiOperation("获取限时优惠分页")
    @PreAuthorize("hasAuthority('marketing.flash-sale.index')")
    @PostMapping("/getFlashSalePage")
    public ResultData<BasePageResp<FlashSaleActivity>> getFlashSalePage(@RequestBody PageReq req) {
        return marketingService.getFlashSalePage(req);
    }

    @ApiOperation("获取限时优惠详情")
    @PreAuthorize("hasAuthority('marketing.flash-sale.flash-sale-edit')")
    @GetMapping("/getFlashSaleDetail")
    public ResultData<FlashSaleEditResp> getFlashSaleDetail(@RequestParam("id") Long id) {
        return marketingService.getFlashSaleDetail(id);
    }

    @ApiOperation("获取限时优惠订阅分页")
    @PostMapping("/getSubscribeRecordPage")
    public ResultData<BasePageResp<SubscribeRecordVO>> getSubscribeRecordPage(@RequestBody SubscribeRecordPageReq req) {
        return marketingService.getSubscribeRecordPage(req);
    }

    @OperatorLog("添加或编辑限时优惠")
    @ApiOperation("添加或编辑限时优惠")
    @PreAuthorize("hasAuthority('marketing.flash-sale.index.edit.auth')")
    @PostMapping("/editFlashSale")
    public BaseResp editFlashSale(@RequestBody FlashSaleEditVO req) {
        return marketingService.editFlashSale(req);
    }

    @OperatorLog("删除限时优惠")
    @ApiOperation("删除限时优惠")
    @PreAuthorize("hasAuthority('marketing.flash-sale.index.delete.auth')")
    @GetMapping("/deleteFlashSale")
    public BaseResp deleteFlashSale(@RequestParam("id") Long id) {
        return marketingService.deleteFlashSale(id);
    }

    @OperatorLog("编辑套餐")
    @ApiOperation("编辑套餐")
    @PreAuthorize("hasAuthority('marketing.package.package-index.edit.auth')")
    @PostMapping("/editPackage")
    public BaseResp editPackage(@RequestBody PackageVO req) {
        return marketingService.editPackage(req);
    }

    @ApiOperation("获取套餐详情")
    @PreAuthorize("hasAuthority('marketing.package.package-edit')")
    @GetMapping("/getPackageDetail")
    public ResultData<PackageResp> getPackageDetail(@RequestParam("id") Long id) {
        return marketingService.getPackageDetail(id);
    }

    @ApiOperation("获取套餐分页")
    @PreAuthorize("hasAuthority('marketing.package.package-index')")
    @PostMapping("/getPackagePage")
    public ResultData<BasePageResp<Packages>> getPackagePage(@RequestBody PageReq req) {
        return marketingService.getPackagePage(req);
    }

    @OperatorLog("删除套餐")
    @ApiOperation("删除套餐")
    @PreAuthorize("hasAuthority('marketing.package.package-edit')")
    @GetMapping("/deletePackage")
    public BaseResp deletePackage(@RequestParam("id") Long id) {
        return marketingService.deletePackage(id);
    }

    @OperatorLog("编辑优惠券")
    @ApiOperation("编辑优惠券")
    @PreAuthorize("hasAuthority('marketing.coupon.coupon-index.edit.auth')")
    @PostMapping("/editCoupon")
    public BaseResp editCoupon(@RequestBody Coupon coupon) {
        return marketingService.editCoupon(coupon);
    }

    @ApiOperation("获取优惠券详情")
    @PreAuthorize("hasAuthority('marketing.coupon.coupon-index.edit.auth')")
    @GetMapping("/getCouponDetail")
    public ResultData<CouponVO> getCouponDetail(@RequestParam("id") Long id) {
        return marketingService.getCouponDetail(id);
    }

    @ApiOperation("获取优惠券分页")
    @PreAuthorize("hasAuthority('marketing.coupon.coupon-index')")
    @PostMapping("/getCouponPage")
    public ResultData<BasePageResp<Coupon>> getCouponPage(@RequestBody PageReq req) {
        return marketingService.getCouponPage(req);
    }

    @OperatorLog("删除优惠券")
    @ApiOperation("删除优惠券")
    @PreAuthorize("hasAuthority('marketing.coupon.coupon-index.edit.auth')")
    @GetMapping("/deleteCoupon")
    public BaseResp deleteCoupon(@RequestParam("id") Long id) {
        return marketingService.deleteCoupon(id);
    }

    @ApiOperation("获取砍价分页")
    @PreAuthorize("hasAuthority('marketing.bargain.index')")
    @PostMapping("/getBargainPage")
    public ResultData<BasePageResp<BargainActivity>> getBargainPage(@RequestBody PageReq req) {
        return bargainService.getBargainPage(req);
    }

    @ApiOperation("获取砍价详情")
    @PreAuthorize("hasAuthority('marketing.bargain.bargain-edit')")
    @GetMapping("/getBargainDetail")
    public ResultData<BargainEditResp> getBargainDetail(@RequestParam("id") Long id) {
        return bargainService.getBargainDetail(id);
    }

    @OperatorLog("添加或编辑砍价")
    @ApiOperation("添加或编辑砍价")
    @PreAuthorize("hasAuthority('marketing.bargain.index.edit.auth')")
    @PostMapping("/editBargain")
    public BaseResp editBargain(@RequestBody BargainEditVO req) {
        return bargainService.editBargain(req);
    }


    @OperatorLog("删除砍价活动")
    @ApiOperation("删除砍价活动")
    @PreAuthorize("hasAuthority('marketing.bargain.index.delete.auth')")
    @GetMapping("/deleteBargain")
    public BaseResp deleteBargain(@RequestParam("id") Long id) {
        return bargainService.deleteBargain(id);
    }

    @ApiOperation("获取砍价记录分页")
    @PreAuthorize("hasAuthority('marketing.bargain.bargain-record')")
    @PostMapping("/getBargainRecordPage")
    public ResultData<BasePageResp<BargainRecordVO>> getBargainRecordPage(@RequestBody PageReq req) {
        return bargainService.getBargainRecordPage(req);
    }

    @ApiOperation("获取好友帮砍明细分页")
    @PreAuthorize("hasAuthority('marketing.bargain.bargain-detail')")
    @PostMapping("/getBargainDetailPage")
    public ResultData<BasePageResp<BargainDetailVO>> getBargainDetailPage(@RequestBody PageReq req) {
        return bargainService.getBargainDetailPage(req);
    }

    @ApiOperation("获取用户兑换卡分页")
    @PreAuthorize("hasAuthority('marketing.cash-card')")
    @PostMapping("/getUserVoucherPage")
    public ResultData<BasePageResp<UserVoucherVO>> getUserVoucherPage(@RequestBody UserVoucherReq req) {
        return marketingService.getUserVoucherPage(req);
    }

    @ApiOperation("获取抽奖机会分页")
    @PostMapping("/getLotteryOpportunityPage")
    public ResultData<BasePageResp<LotteryOpportunityVO>> getLotteryOpportunityPage(@RequestBody LotteryOpportunityPageReq req) {
        return marketingService.getLotteryOpportunityPage(req);
    }

}
